package obs;

import javax.jdo.PersistenceManager;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable
public class UserData {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
    private String encodedKey;
    @Persistent
    private String grade;
    @Persistent
    private String email;
    @Persistent
    private String age;
    @Persistent
    private int pool;
    @Persistent
    private int[] pairings;
    @Persistent
    private int pairingId;
    @Persistent
    private int[] responses;

    // Send this object to the database
    public void persist() {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            pm.makePersistent(this);
        } finally {
            pm.close();
        }
    }

    public static UserData getUserDataByKey(String key) {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            return (UserData) pm.getObjectById(UserData.class, key);
        } finally {
            pm.close();
        }

    }

    /**
     * @return the encodedKey
     */
    public String getEncodedKey() {
        return encodedKey;
    }

    /**
     * @param encodedKey the encodedKey to set
     */
    public void setEncodedKey(String encodedKey) {
        this.encodedKey = encodedKey;
    }

    /**
     * @return the username
     */
    public String getGrade() {
        return grade;
    }

    /**
     * @param username the username to set
     */
    public void setGrade(String grade) {
        this.grade = grade;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the age
     */
    public String getAge() {
        return age;
    }

    /**
     * @param age the age to set
     */
    public void setAge(String age) {
        this.age = age;
    }

    /**
     * @return the pairings
     */
    public int[] getPairings() {
        return pairings;
    }

    /**
     * @param pairings the pairings to set
     */
    public void setPairings(int[] pairings) {
        this.pairings = pairings;
    }

    /**
     * @return the pairingId
     */
    public int getPairingId() {
        return pairingId;
    }

    /**
     * @param pairingId the pairingId to set
     */
    public void setPairingId(int pairingId) {
        this.pairingId = pairingId;
    }

    /**
     * @return the pool
     */
    public int getPool() {
        return pool;
    }

    /**
     * @param pool the pool to set
     */
    public void setPool(int pool) {
        this.pool = pool;
    }

    /**
     * @return the responses
     */
    public int[] getResponses() {
        return responses;
    }

    /**
     * @param responses the responses to set
     */
    public void setResponses(int[] responses) {
        this.responses = responses;
    }
}
